package com.nanako.service.impl;

import com.nanako.dao.StaticsDao;
import com.nanako.entity.*;
import com.nanako.service.*;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;

@Service
public class StaticsServiceImpl implements StaticsService {
    @Autowired
    private StaticsDao staticsDao;

    @Override
    public List<Cash> dishCash() {
        return staticsDao.getDishCash();
    }

    @Override
    public List<Cash> setmealCash() {
        return staticsDao.getSetmealCash();
    }

    @Override
    public List<Cash> dishNum() {
        return staticsDao.getDishNum();
    }

    @Override
    public List<Cash> setmealNum() {
        return staticsDao.getSetmealNum();
    }

    @Override
    public Map<Object, Object> cashPerMonth() {
        LocalDateTime now = LocalDateTime.now();
        DateTimeFormatter format = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        LinkedList<Long> amounts = new LinkedList<>();
        for (int i = 0; i < 11; i++) {
            String endTime = format.format(now);
            now = now.minusMonths(1L);
            String beginTime = format.format(now);
            Long amount = staticsDao.getCashPerMonth(beginTime, endTime);
            if (ObjectUtils.isNotEmpty(amount)) {
                amount /= 10000;
            }
            amounts.push(amount);
        }
        HashMap<Object, Object> hashMap = new HashMap<>();
        hashMap.put("dataList", amounts);
        return hashMap;
    }


}
